import { defineStore } from "pinia";
import { computed, reactive, ref } from "vue";
//用户模块
export const useToDoStore = defineStore(
  "big-todos",
  () => {
    const newItem = ref("");
    const items = reactive([]);
    const counts = computed(() => items.length);
    function addToDo() {
      items.push({
        id: items.length + 1,
        text: newItem.value.trim(),
      });
      newItem.value = "";
    }
    const removeitem = (item) => {
      const index = items.indexOf(item);
      items.splice(index, 1);
    };

    return {
      newItem,
      counts,
      items,
      addToDo,
      removeitem,
    };
  },
  {
    persist: {
      storage: localStorage,
      paths: ["items"],
    },
  }
);
